package com.kiseny.main;

import java.io.File;
import java.util.List;

import com.common.operator.PlainFileOperator;
import com.common.util.Constants;


public class UpdateTXT {
	
	private static final String PATH_SOURCE = "D:/2011/txtdata/";

	/**
<= 10RMB                 * 3
quantity 1-2             * 3
         3-10            * 2.95
         11-30           * 2.90
         31-100          * 2.85
         100-199         * 2.80
10< x <=20RMB            * 2.5
quantity 1-2             * 2.5
         3-10            * 2.45
         11-30           * 2.40
         31-100          * 2.35
         100-199         * 2.30
20< x <9999RMB           * 2
quantity 1-2             * 2.0
         3-10            * 1.95
         11-30           * 1.90
         31-100          * 1.85
         100-199         * 1.80
	 * @param args
	 */
	public static void main(String[] args) throws Exception {

		File root = new File(PATH_SOURCE);
		showAllFiles(root);

	}

	private static void showAllFiles(File dir) throws Exception {
		File[] fs = dir.listFiles();
		for (int i = 0; i < fs.length; i++) {
			System.out.println(fs[i].getAbsolutePath());
			if (fs[i].isDirectory()) {
				try {
					showAllFiles(fs[i]);
				} catch (Exception e) {
				}
			} else if (fs[i].isFile() && fs[i].getName().endsWith(".txt")) {
				List<String> contentList = PlainFileOperator.readByLine(fs[i]);

				fs[i].delete();
				for (String s : contentList) {
				  System.out.println(s);
				  
				  PlainFileOperator.writeByLine(fs[i], s);
				  
				  if (s.startsWith("\u6279\u53d1\u4ef7\uff1a")) {
					  
					  String[] lineArray = s.split("\uff1a");
					  float originalPrice = Float.parseFloat(lineArray[1]);
					  float finalPrice = getFinalPrice(originalPrice);
					  PlainFileOperator.writeByLine(fs[i], Constants.MARKS_WIN_LF);
					  PlainFileOperator.writeByLine(fs[i], "Kiseny Price: " + finalPrice);
				  }
				}

			} else {
				//Empty
			}
		}
	}

	private static float getFinalPrice(float originalPrice) {
		
		return 100;
	}
}